/**
 * 作者: lipengfei
 * 日期: 2022-01-23 14:11:11
 * 备注: 用户每日签到数据
 */
package com.motu.monstercity.server.game.userdata;


import com.motu.monstercity.protocol.Common.PBUserDailySign;
import com.motu.monstercity.server.game.base.AllParam;
import com.motu.monstercity.server.game.commondata.act.DailySign;
import com.motu.monstercity.server.game.logic.ActManager;
import com.motu.vertx.module.utility.toolset.TimeUtils;
import com.motu.vertx.module.utility.toolset.Tool;

import java.util.List;

public class UserDailySign extends UserDailySignModel {

    public static final byte NO = 0;
    public static final byte YES = 1;

    public UserDailySign() {
        super();
    }

    public void reset() {
        if (!TimeUtils.isToday(resetTime)) {
            putResetTime(TimeUtils.getCurTime());
            if (type == 0) {
                putType(1);
            }
            if (day == 0) {
                putDay(1);
            }
            if (isReward == YES) {
                List<DailySign> dailySignList = ActManager.getDailySignList(type);
                if (dailySignList != null && day == dailySignList.size()) {
                    if (dailySignList != null && day == dailySignList.size()) {
                        if (type == AllParam.SIGN_REPEAT[1]) {
                            putType(AllParam.SIGN_REPEAT[0]);
                        } else {
                            addType(1);
                        }
                    }
                    putDay(1);
                } else {
                    addDay(1);
                }
            }
            putIsCharge(NO);
            putIsReward(NO);
            putIsChargeReward(NO);
            putIsWatchAd(NO);
            putIsAdReward(NO);
            update();
        }
    }

    public PBUserDailySign.Builder takeInitBuilder() {
        PBUserDailySign.Builder builder = super.takeInitBuilder();
        if (isCharge != 0) {
            builder.setIsCharge(true);
        }
        if (isChargeReward != 0) {
            builder.setIsChargeReward(true);
        }
        if (isReward != 0) {
            builder.setIsReward(true);
        }
        if (isWatchAd != 0) {
            builder.setIsWatchAd(true);
        }
        if (isAdReward != 0) {
            builder.setIsAdReward(true);
        }
        return builder;
    }

    public PBUserDailySign.Builder takeBuilder() {
        PBUserDailySign.Builder builder = super.takeBuilder();
        if (isFieldUpdate("isCharge")) {
            builder.setIsCharge(isCharge());
        }
        if (isFieldUpdate("isChargeReward")) {
            builder.setIsChargeReward(isChargeReward());
        }
        if (isFieldUpdate("isReward")) {
            builder.setIsReward(isReward());
        }
        if (isFieldUpdate("isWatchAd")) {
            builder.setIsWatchAd(isWatchAd());
        }
        if (isFieldUpdate("isAdReward")) {
            builder.setIsAdReward(isAdReward());
        }
        return builder;
    }

    public boolean isReward() {
        return isReward == YES;
    }

    public boolean isCharge() {
        return isCharge == YES;
    }

    public boolean isChargeReward() {
        return isChargeReward == YES;
    }

    public boolean isWatchAd() {
        return isWatchAd == YES;
    }
    public boolean isAdReward() {
        return isAdReward == YES;
    }

}
